{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "### How to run\n",
    "\n",
    "```sh\n",
    "pixi run -e examples py-build-common\n",
    "pixi run -e examples py-build-notebook\n",
    "pixi run -e examples jupyter notebook examples/python/notebook/send_table.ipynb\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1",
   "metadata": {},
   "source": [
    "## Inline viewer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import annotations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "os.environ[\"RERUN_NOTEBOOK_ASSET\"] = \"inline\"\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import pyarrow as pa\n",
    "from rerun.notebook import Viewer"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4",
   "metadata": {},
   "source": [
    "### Send a basic table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5",
   "metadata": {},
   "outputs": [],
   "source": [
    "viewer = Viewer(width=500, height=300)\n",
    "viewer.display()\n",
    "viewer.send_table(\n",
    "    \"Hello from Notebook\",\n",
    "    pa.RecordBatch.from_pydict({\"Column A\": [1, 2, 3], \"Column B\": [\"https://www.rerun.io\", \"Hello\", \"World\"]}),\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6",
   "metadata": {},
   "source": [
    "### Send a Pandas dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7",
   "metadata": {},
   "outputs": [],
   "source": [
    "dates = pd.date_range(\"20130101\", periods=6)\n",
    "df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list(\"ABCD\"))\n",
    "df_reset = df.reset_index().rename(columns={\"index\": \"date\"})\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8",
   "metadata": {},
   "source": [
    "### Send a Pandas dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9",
   "metadata": {},
   "outputs": [],
   "source": [
    "viewer = Viewer(width=\"auto\", height=350)\n",
    "viewer.display()\n",
    "viewer.send_table(\"Hello from Pandas\", pa.RecordBatch.from_pandas(df))"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 5
}
